package com.zygame.sdk.view.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.zygame.sdk.ConstantValue;
import com.zygame.sdk.utils.res.ResourceUtil;

/**
 * Created by Yuxl on 2017/9/28.
 *
 *
 */

public class Zy_Dialog_PayWay extends ZY_BaseDialog {
    private Context context;
    private View view;
    private String mAccoutn;
    private String mPwd;
    private boolean isBack;
    private String randomPassword;
    private String user_name;
    private static Zy_Dialog_PayWay dialog_payway;
    private IPayWaySelectListener mIPayWaySelectListener;
    private ImageView mIv_payPal;
    private ImageView mIv_google;
    private TextView mRechargeMoney;
    private ImageView mIv_payPal_selected;
    private ImageView mIv_google_selected;

    public void setIPayWaySelectListener(String payMoney,IPayWaySelectListener IPayWaySelectListener) {
        mIPayWaySelectListener = IPayWaySelectListener;
        mRechargeMoney.setText("$" + payMoney);
    }

    public static Zy_Dialog_PayWay getInstance(Context context){
        if(null == dialog_payway){
            dialog_payway = new Zy_Dialog_PayWay(context);
        }
        return dialog_payway;
    }




    private Zy_Dialog_PayWay(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void init() {
        showClose(true);
        Button btn_recharge = findViewById(ResourceUtil.getId(context, "btn_recharge"));
        mIv_payPal = findViewById(ResourceUtil.getId(context, "iv_PayPal"));
        mIv_google = findViewById(ResourceUtil.getId(context, "iv_Google"));

        mIv_payPal_selected = findViewById(ResourceUtil.getId(context, "iv_PayPal_selected"));
        mIv_google_selected = findViewById(ResourceUtil.getId(context, "iv_Google_selected"));
        mRechargeMoney = findViewById(ResourceUtil.getId(context, "tv_recharge_money"));

        mIv_payPal.setSelected(true);

        if(ConstantValue.ZY_SHOWBACK){
            btn_back.setVisibility(View.VISIBLE);
        }
        btn_recharge.setOnClickListener(this);
        mIv_payPal.setOnClickListener(this);
        mIv_google.setOnClickListener(this);
    }


    @Override
    protected String getResourceStr() {
        return "zy_dialog_pay_way";
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        int ids = v.getId();
        if (ResourceUtil.getId(context, "btn_recharge") == ids) {//充值
            mIPayWaySelectListener.onSelectedPayWay(mIv_payPal.isSelected()? 0 : 1);
            dismiss();
        }else if(ids == ResourceUtil.getId(context,"btn_back")){
            dismiss();
        }else if(ids == ResourceUtil.getId(context,"iv_PayPal")){
            mIv_payPal.setSelected(true);
            mIv_google.setSelected(false);
            mIv_payPal_selected.setVisibility(View.VISIBLE);
            mIv_google_selected.setVisibility(View.GONE);
        }else if(ids == ResourceUtil.getId(context,"iv_Google")){
            mIv_google.setSelected(true);
            mIv_payPal.setSelected(false);
            mIv_payPal_selected.setVisibility(View.GONE);
            mIv_google_selected.setVisibility(View.VISIBLE);
        }
    }

    public void dissDialog(){
        dialog_payway.dismiss();
        dialog_payway = null;
    }

    public interface IPayWaySelectListener{
        void onSelectedPayWay(int payWay);
    }
}
